/**

 * @author hanzhendong

 * @date 2023/8/23 13:57

 */

import Vue from 'vue'
import { getDicData } from '@/api';
// 引入自己获取字典的接口

export default class Dict {
  constructor(dict) {
    this.dict = dict
  }

  async init(names, completeCallback) {
    if (names === undefined || name === null) {
      throw new Error('need Dict names')
    }
    const ps = []
    names.forEach(name => {
      Vue.set(this.dict, name, [])
      ps.push(getDicData(name).then(data => {
        (data||[]).forEach(item => {item.label=item.name})
        this.dict[name] = Object.freeze(data);
      }))
    })
    await Promise.all(ps)
    completeCallback()
  }
}

